import React from 'react';
import copy from 'copy-to-clipboard';
import CopyText from '@/components/copy';
import cn from 'classnames';
import s from './style.module.css';

import { Message,Tooltip } from '@knownsec/react-component';
function CopyBoard({ text,maxWidth,className }) {
  const nodeRef = React.useRef();

  const handleCopyText = () => {
    if (copy(text)) {
      Message.show({
        pro: true,
        type: 'success',
        message: '内容已复制！',
        showClose: false,
      });
    }
  };
  return (
    <Tooltip
      overlay={
        <p>
          <span className={cn(s.content)}>{text}</span> 点击复制
        </p>
      }
      placement="topLeft"
    >
      <span
        className={cn(className, s.copyBoard)}
        ref={nodeRef}
        onClick={handleCopyText}
        style={{ maxWidth }}
      >
        {text}
      </span>
    </Tooltip>
  );
}
export default CopyBoard;
